var e = require("../../@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", { value: !0 }),
  (exports.default = void 0);
var t = require("../../@babel/runtime/helpers/classCallCheck"),
  n = require("../../@babel/runtime/helpers/createClass"),
  i = require("../../@babel/runtime/helpers/inherits"),
  a = require("../../@babel/runtime/helpers/createSuper"),
  o = (function (e) {
    i(s, e);
    var o = a(s);
    function s() {
      var e,
        n = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
      return (
        t(this, s),
        ((e = o.call(this)).started = !1),
        (e.systemInfo = n.systemInfo),
        (e._heading = 0),
        (e.deviceMotionData = { alpha: 0, beta: 0, gamma: 0 }),
        (e.onDeviceMotionChangeHandler = function (t) {
          (e.deviceMotionData = t),
            "android" == e.systemInfo.platform
              ? (e.deviceMotionData = Object.assign(e.deviceMotionData, {
                  alpha: t.alpha,
                  beta: -t.beta,
                }))
              : (e.deviceMotionData.alpha = e._heading),
            e.emitEvent();
        }),
        (e.onCompassChangeHandler = function (t) {
          e._heading = t.direction;
        }),
        e
      );
    }
    return (
      n(s, [
        {
          key: "emitEvent",
          value: function () {
            var e = new Date().getTime(),
              t = this.deviceMotionData.alpha;
            this.emit("md_deviceMotionChange", {
              value: this.deviceMotionData,
              timestamp: e,
            }),
              this.emit("md_headingChanged", {
                value: { heading: t, event: this.deviceMotionData },
                timestamp: e,
              });
          },
        },
        {
          key: "start",
          value: function () {
            var e = this;
            this.started ||
              ((this.started = !0),
              "ios" == this.systemInfo.platform &&
                (wx.startCompass({
                  success: function (e) {},
                  fail: function (e) {},
                  complete: function (e) {},
                }),
                wx.onCompassChange(this.onCompassChangeHandler)),
              wx.startDeviceMotionListening({
                interval: "game",
                success: function (e) {},
                fail: function (e) {},
                complete: function (t) {
                  e.started || e.stop();
                },
              }),
              wx.onDeviceMotionChange(this.onDeviceMotionChangeHandler));
          },
        },
        {
          key: "stop",
          value: function () {
            (this.started = !1),
              "ios" == this.systemInfo.platform &&
                (wx.offCompassChange &&
                  wx.offCompassChange(this.onCompassChangeHandler),
                wx.stopCompass({
                  success: function (e) {},
                  fail: function (e) {},
                  complete: function (e) {},
                })),
              wx.offDeviceMotionChange &&
                wx.offDeviceMotionChange(this.onDeviceMotionChangeHandler),
              wx.stopDeviceMotionListening({
                success: function (e) {},
                fail: function (e) {},
                complete: function (e) {},
              });
          },
        },
      ]),
      s
    );
  })(e(require("../common/EventDispatcher.js")).default);
exports.default = o;
